// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.util;

import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.util.Objects;

public class ByteBufferBackedInputStream extends InputStream {
    final ByteBuffer buf;

    public ByteBufferBackedInputStream(ByteBuffer _buf) {
        Objects.requireNonNull(_buf);
        this.buf = _buf;
    }

    public int read() throws IOException {
        return !this.buf.hasRemaining() ? -1 : this.buf.get() & 0xFF;
    }

    public int read(byte[] _byte, int int1, int int0) throws IOException {
        if (!this.buf.hasRemaining()) {
            return -1;
        } else {
            int0 = Math.min(int0, this.buf.remaining());
            this.buf.get(_byte, int1, int0);
            return int0;
        }
    }
}
